package com.xpxrule.function;

import com.googlecode.aviator.runtime.function.AbstractFunction;
import com.googlecode.aviator.runtime.type.AviatorBoolean;
import com.googlecode.aviator.runtime.type.AviatorObject;

import java.math.BigDecimal;
import java.util.Map;

public class BigDecimalLessThanFunction extends AbstractFunction {
    @Override
    public String getName() {
        return AviatorCustomFunctionContext.CustomFunctionName.BIG_DECIMAL_LESS_THAN;
    }

    @Override
    public AviatorObject call(Map<String, Object> env, AviatorObject arg1, AviatorObject arg2) {
        BigDecimal leftValue = (BigDecimal) arg1.getValue(env);
        BigDecimal rightValue = new BigDecimal(String.valueOf(arg2.getValue(env)));
        return AviatorBoolean.valueOf(leftValue.compareTo(rightValue) < 0);
    }
}
